using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VKAREZEPT
    {
        public DataRow Convert2KAREZEPT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryKAREZEPT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["KARMANDANT"] = " ".PadRight(2 ); 
         dwReturn["KARKANR"] = " ".PadRight(8 ); 
         dwReturn["KARKAPOS"] = " ".PadRight(4 ); 
         dwReturn["KARVPOS"] = " ".PadRight(2 ); 
         dwReturn["KARAFOLGE"] = " ".PadRight(3 ); 
         dwReturn["KARFOLGEPOS"] = " ".PadRight(3 ); 
         dwReturn["KARAENZL"] = " ".PadRight(0 ); 
         dwReturn["KARAENB"] = " ".PadRight(8 ); 
         dwReturn["KARAEND"] = " ".PadRight(0 ); 
         dwReturn["KARNEUB"] = " ".PadRight(8 ); 
         dwReturn["KARNEUD"] = " ".PadRight(0 ); 
         dwReturn["KARSA"] = " ".PadRight(1 ); 
         dwReturn["KARREZEPTKZ"] = " ".PadRight(1 ); 
         dwReturn["KARREZEPTNR"] = " ".PadRight(10 ); 
         dwReturn["KARREZEPTST"] = " ".PadRight(1 ); 
         dwReturn["KARFLOTTE"] = " ".PadRight(0 ); 
         dwReturn["KARFKLTR"] = " ".PadRight(0 ); 
         dwReturn["KARCKLTR"] = " ".PadRight(0 ); 
         dwReturn["KARFKMTR"] = " ".PadRight(0 ); 
         dwReturn["KARCKMTR"] = " ".PadRight(0 ); 
         dwReturn["KARAUFL"] = " ".PadRight(0 ); 
         dwReturn["KARRFILLER"] = " ".PadRight(50 ); 
         dwReturn["KARMAT"] = " ".PadRight(14 ); 
         dwReturn["KARVAR"] = " ".PadRight(3 ); 
         dwReturn["KARVERBME"] = " ".PadRight(0 ); 
         dwReturn["KARVERBMEH"] = " ".PadRight(3 ); 
         dwReturn["KARKOME"] = " ".PadRight(0 ); 
         dwReturn["KARKOMEH"] = " ".PadRight(3 ); 
         dwReturn["KARMFILLER"] = " ".PadRight(50 ); 
         dwReturn["KARVERLUST"] = " ".PadRight(0 ); 
         dwReturn["KARKOPAUF"] = " ".PadRight(0 ); 
         dwReturn["KARMGK01"] = " ".PadRight(0 ); 
         dwReturn["KARMGK02"] = " ".PadRight(0 ); 
         dwReturn["KARMGK03"] = " ".PadRight(0 ); 
         dwReturn["KARMGK04"] = " ".PadRight(0 ); 
         dwReturn["KARMGK05"] = " ".PadRight(0 ); 
         dwReturn["KARFILLER"] = " ".PadRight(58 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapKAREZEPT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveKAREZEPT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryKAREZEPT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapKAREZEPT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertKAREZEPT(dwLocal, ITXDBVERSION);
            }
            UpdateKAREZEPT(dwLocal);
        }
        public void InsertKAREZEPT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO KAREZEPT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryKAREZEPT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM KAREZEPT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM KAREZEPT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "KAREZEPT";
            Return = Result;
            return Return;
        }
        public void DeleteKAREZEPT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM KAREZEPT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateKAREZEPT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE KAREZEPT SET "
                    +"KARMANDANT= :KARMANDANT,"
                    +"KARKANR= :KARKANR,"
                    +"KARKAPOS= :KARKAPOS,"
                    +"KARVPOS= :KARVPOS,"
                    +"KARAFOLGE= :KARAFOLGE,"
                    +"KARFOLGEPOS= :KARFOLGEPOS,"
                    +"KARAENZL= :KARAENZL,"
                    +"KARAENB= :KARAENB,"
                    +"KARAEND= :KARAEND,"
                    +"KARNEUB= :KARNEUB,"
                    +"KARNEUD= :KARNEUD,"
                    +"KARSA= :KARSA,"
                    +"KARREZEPTKZ= :KARREZEPTKZ,"
                    +"KARREZEPTNR= :KARREZEPTNR,"
                    +"KARREZEPTST= :KARREZEPTST,"
                    +"KARFLOTTE= :KARFLOTTE,"
                    +"KARFKLTR= :KARFKLTR,"
                    +"KARCKLTR= :KARCKLTR,"
                    +"KARFKMTR= :KARFKMTR,"
                    +"KARCKMTR= :KARCKMTR,"
                    +"KARAUFL= :KARAUFL,"
                    +"KARRFILLER= :KARRFILLER,"
                    +"KARMAT= :KARMAT,"
                    +"KARVAR= :KARVAR,"
                    +"KARVERBME= :KARVERBME,"
                    +"KARVERBMEH= :KARVERBMEH,"
                    +"KARKOME= :KARKOME,"
                    +"KARKOMEH= :KARKOMEH,"
                    +"KARMFILLER= :KARMFILLER,"
                    +"KARVERLUST= :KARVERLUST,"
                    +"KARKOPAUF= :KARKOPAUF,"
                    +"KARMGK01= :KARMGK01,"
                    +"KARMGK02= :KARMGK02,"
                    +"KARMGK03= :KARMGK03,"
                    +"KARMGK04= :KARMGK04,"
                    +"KARMGK05= :KARMGK05,"
                    +"KARFILLER= :KARFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("KARMANDANT", OracleType.NVarChar).Value = dwData["KARMANDANT"].ToString(); 
          or1.Parameters.Add("KARKANR", OracleType.NVarChar).Value = dwData["KARKANR"].ToString(); 
          or1.Parameters.Add("KARKAPOS", OracleType.NVarChar).Value = dwData["KARKAPOS"].ToString(); 
          or1.Parameters.Add("KARVPOS", OracleType.NVarChar).Value = dwData["KARVPOS"].ToString(); 
          or1.Parameters.Add("KARAFOLGE", OracleType.NVarChar).Value = dwData["KARAFOLGE"].ToString(); 
          or1.Parameters.Add("KARFOLGEPOS", OracleType.NVarChar).Value = dwData["KARFOLGEPOS"].ToString(); 
          or1.Parameters.Add("KARAENZL", OracleType.NVarChar).Value = dwData["KARAENZL"].ToString(); 
          or1.Parameters.Add("KARAENB", OracleType.NVarChar).Value = dwData["KARAENB"].ToString(); 
          or1.Parameters.Add("KARAEND", OracleType.NVarChar).Value = dwData["KARAEND"].ToString(); 
          or1.Parameters.Add("KARNEUB", OracleType.NVarChar).Value = dwData["KARNEUB"].ToString(); 
          or1.Parameters.Add("KARNEUD", OracleType.NVarChar).Value = dwData["KARNEUD"].ToString(); 
          or1.Parameters.Add("KARSA", OracleType.NVarChar).Value = dwData["KARSA"].ToString(); 
          or1.Parameters.Add("KARREZEPTKZ", OracleType.NVarChar).Value = dwData["KARREZEPTKZ"].ToString(); 
          or1.Parameters.Add("KARREZEPTNR", OracleType.NVarChar).Value = dwData["KARREZEPTNR"].ToString(); 
          or1.Parameters.Add("KARREZEPTST", OracleType.NVarChar).Value = dwData["KARREZEPTST"].ToString(); 
          or1.Parameters.Add("KARFLOTTE", OracleType.NVarChar).Value = dwData["KARFLOTTE"].ToString(); 
          or1.Parameters.Add("KARFKLTR", OracleType.NVarChar).Value = dwData["KARFKLTR"].ToString(); 
          or1.Parameters.Add("KARCKLTR", OracleType.NVarChar).Value = dwData["KARCKLTR"].ToString(); 
          or1.Parameters.Add("KARFKMTR", OracleType.NVarChar).Value = dwData["KARFKMTR"].ToString(); 
          or1.Parameters.Add("KARCKMTR", OracleType.NVarChar).Value = dwData["KARCKMTR"].ToString(); 
          or1.Parameters.Add("KARAUFL", OracleType.NVarChar).Value = dwData["KARAUFL"].ToString(); 
          or1.Parameters.Add("KARRFILLER", OracleType.NVarChar).Value = dwData["KARRFILLER"].ToString(); 
          or1.Parameters.Add("KARMAT", OracleType.NVarChar).Value = dwData["KARMAT"].ToString(); 
          or1.Parameters.Add("KARVAR", OracleType.NVarChar).Value = dwData["KARVAR"].ToString(); 
          or1.Parameters.Add("KARVERBME", OracleType.NVarChar).Value = dwData["KARVERBME"].ToString(); 
          or1.Parameters.Add("KARVERBMEH", OracleType.NVarChar).Value = dwData["KARVERBMEH"].ToString(); 
          or1.Parameters.Add("KARKOME", OracleType.NVarChar).Value = dwData["KARKOME"].ToString(); 
          or1.Parameters.Add("KARKOMEH", OracleType.NVarChar).Value = dwData["KARKOMEH"].ToString(); 
          or1.Parameters.Add("KARMFILLER", OracleType.NVarChar).Value = dwData["KARMFILLER"].ToString(); 
          or1.Parameters.Add("KARVERLUST", OracleType.NVarChar).Value = dwData["KARVERLUST"].ToString(); 
          or1.Parameters.Add("KARKOPAUF", OracleType.NVarChar).Value = dwData["KARKOPAUF"].ToString(); 
          or1.Parameters.Add("KARMGK01", OracleType.NVarChar).Value = dwData["KARMGK01"].ToString(); 
          or1.Parameters.Add("KARMGK02", OracleType.NVarChar).Value = dwData["KARMGK02"].ToString(); 
          or1.Parameters.Add("KARMGK03", OracleType.NVarChar).Value = dwData["KARMGK03"].ToString(); 
          or1.Parameters.Add("KARMGK04", OracleType.NVarChar).Value = dwData["KARMGK04"].ToString(); 
          or1.Parameters.Add("KARMGK05", OracleType.NVarChar).Value = dwData["KARMGK05"].ToString(); 
          or1.Parameters.Add("KARFILLER", OracleType.NVarChar).Value = dwData["KARFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
